package com.wanbang.sale.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wanbang.sale.commonutils.R;
import com.wanbang.sale.entity.Aixs;
import com.wanbang.sale.entity.aixsVo.AixsPage;
import com.wanbang.sale.entity.aixsVo.SaleQuery;
import com.wanbang.sale.service.AixsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-10-29
 */
@Api(description="销售管理")
@CrossOrigin
@RestController
@RequestMapping("/sale/aixs")
public class AixsController {

    @Autowired
    private AixsService aixsService;

    @GetMapping("/detail")
    public R detail() {
        return R.ok();
    }

    @GetMapping("/getList")
    public R getList() {

        List<Aixs> list = aixsService.list(new QueryWrapper<Aixs>().last("where rownum < 6"));

        return R.ok().data("aixsList",list);

    }

    /**
     * 分页查询
     * @param page 分页对象
     * @param aixs
     * @return
     */
    @ApiOperation("分页查询")
    @GetMapping("/page")
    public R getExamMockPage(Page page, Aixs aixs) {

        IPage page1 = aixsService.page(page, Wrappers.query(aixs));

        return R.ok().data("list",page1);

    }

    @ApiOperation(value = "分页销售列表")
    @GetMapping("{page}/{limit}")
    public R pageQuery(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Long page,

            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Long limit,

            @ApiParam(name = "saleQuery", value = "查询对象", required = false)
                    SaleQuery saleQuery){

        Page<Aixs> pageParam = new Page<>(page, limit);

        aixsService.pageQuery(pageParam, saleQuery);
        List<Aixs> records = pageParam.getRecords();
        long total = pageParam.getTotal();

        return  R.ok().data("total", total).data("rows", records);

    }




}

